package tam;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.testing.RobotTestBed;

/**
 * Behavioral test. Checks if ranged enemy robot runs out of energy before dying.
 * If this is true, then Ringer's stalling tactics worked on it.
 *
 * @author Micah Takabayashi
 */
public class TestRingerMovement extends RobotTestBed {
  
  private boolean enemyDepleted = false;
  
  /**
   * Specifies that Corners and Ringer are to be matched up in this test case.
   *
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Corners,tam.Ringer";
  }

  /**
   * This test runs for 1 round.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 1;
  }

  /**
   * After each turn, checks if enemy is both alive and out of energy.
   *
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    
    boolean enemyIsAlive = event.getTurnSnapshot().getRobots()[0].getState().isAlive();
    double enemyEnergy = event.getTurnSnapshot().getRobots()[0].getEnergy();
    
    if (enemyIsAlive && enemyEnergy <= 0) {
      this.enemyDepleted = true;
    }
  }
  
  /**
   * After the battle, if enemy energy was depleted before it was killed, test is passed.
   *
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Enemy Depleted", this.enemyDepleted);
  }
}